package ru.evga.common.query;

import java.util.List;

public class QueryBuilder
{
    private StringBuilder sb;
    private List<Object> params;
    private String SPACE = " ";
    private String WHERE = "WHERE";

    private String EQ = "=";
    private String G = ">";
    private String GE = ">=";
    private String L = ">=";
    private String LE = "<=";
    private boolean firstCondition = true;

    public QueryBuilder(StringBuilder sb, List<Object> params)
    {
        this.sb = sb;
        this.params = params;
        sb.append(SPACE)
        .append(WHERE);
    }
    
    
    public QueryBuilder and()
    {
        if (!firstCondition)
        {
            sb.append(SPACE)
            .append("AND");
        }
        return this;
    }
    
    public QueryBuilder or()
    {
        if (!firstCondition)
        {
            sb.append(SPACE)
            .append("OR");
        }
        return this;
    }
    
    public QueryBuilder eq(String paramName, Object value)
    {
        condition(paramName, value, EQ);
        return this;
    }

    public QueryBuilder g(String paramName, Object value)
    {
        condition(paramName, value, G);
        return this;
    }
    
    public QueryBuilder ge(String paramName, Object value)
    {
        condition(paramName, value, GE);
        return this;
    }
    
    public QueryBuilder l(String paramName, Object value)
    {
        condition(paramName, value, L);
        return this;
    }
    
    public QueryBuilder le(String paramName, Object value)
    {
        condition(paramName, value, LE);
        return this;
    }

    public QueryBuilder condition(String paramName, Object value, String condition)
    {
        sb.append(SPACE)
        .append(paramName)
        .append(condition)
        .append("?");
        params.add(value);
        firstCondition = false;
        return this;
    }
    
    
    
    
}
